<template>
  <div class="homeForm">
    <el-form :inline="true" :model="formData" :rules="rules" ref="form">
      <el-form-item label="行数" prop="row">
        <el-input
          v-model.number="formData.row"
          placeholder="请输入行数"
        ></el-input>
      </el-form-item>
      <el-form-item label="列数" prop="column">
        <el-input
          v-model.number="formData.column"
          placeholder="请输入列数"
        ></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">生成表格</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      formData: {
        row: null,
        column: null
      },
      rules: {
        row: [
          { required: true, message: "行数不能为空" },
          { type: "number", message: "行数必须为数字值" }
        ],
        column: [
          { required: true, message: "行数不能为空" },
          { type: "number", message: "行数必须为数字值" }
        ]
      }
    };
  },
  methods: {
    onSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.$emit("input", this.formData);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  }
};
</script>
